from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-04 14:02:26.903955
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 04, Apr, 2022
Time: 14:02:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.8261
Nobs: 616.000 HQIC: -49.2211
Log likelihood: 7460.89 FPE: 3.26920e-22
AIC: -49.4724 Det(Omega_mle): 2.82812e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.338147 0.065018 5.201 0.000
L1.Burgenland 0.106070 0.040168 2.641 0.008
L1.Kärnten -0.110585 0.021015 -5.262 0.000
L1.Niederösterreich 0.195019 0.083972 2.322 0.020
L1.Oberösterreich 0.119513 0.082698 1.445 0.148
L1.Salzburg 0.259241 0.042606 6.085 0.000
L1.Steiermark 0.041867 0.056168 0.745 0.456
L1.Tirol 0.104353 0.045358 2.301 0.021
L1.Vorarlberg -0.066201 0.040075 -1.652 0.099
L1.Wien 0.019219 0.073688 0.261 0.794
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.051375 0.139357 0.369 0.712
L1.Burgenland -0.038198 0.086095 -0.444 0.657
L1.Kärnten 0.042051 0.045042 0.934 0.351
L1.Niederösterreich -0.202055 0.179981 -1.123 0.262
L1.Oberösterreich 0.455388 0.177251 2.569 0.010
L1.Salzburg 0.282714 0.091320 3.096 0.002
L1.Steiermark 0.112986 0.120387 0.939 0.348
L1.Tirol 0.306154 0.097219 3.149 0.002
L1.Vorarlberg 0.026858 0.085895 0.313 0.755
L1.Wien -0.028573 0.157939 -0.181 0.856
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.194712 0.033200 5.865 0.000
L1.Burgenland 0.088521 0.020511 4.316 0.000
L1.Kärnten -0.007174 0.010731 -0.669 0.504
L1.Niederösterreich 0.243620 0.042879 5.682 0.000
L1.Oberösterreich 0.160732 0.042228 3.806 0.000
L1.Salzburg 0.039976 0.021756 1.837 0.066
L1.Steiermark 0.027835 0.028681 0.971 0.332
L1.Tirol 0.082563 0.023161 3.565 0.000
L1.Vorarlberg 0.054253 0.020464 2.651 0.008
L1.Wien 0.116831 0.037627 3.105 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.113715 0.033238 3.421 0.001
L1.Burgenland 0.042709 0.020534 2.080 0.038
L1.Kärnten -0.013063 0.010743 -1.216 0.224
L1.Niederösterreich 0.173516 0.042927 4.042 0.000
L1.Oberösterreich 0.334925 0.042276 7.922 0.000
L1.Salzburg 0.100022 0.021781 4.592 0.000
L1.Steiermark 0.113420 0.028713 3.950 0.000
L1.Tirol 0.090761 0.023188 3.914 0.000
L1.Vorarlberg 0.060737 0.020487 2.965 0.003
L1.Wien -0.017230 0.037670 -0.457 0.647
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120047 0.062247 1.929 0.054
L1.Burgenland -0.046123 0.038456 -1.199 0.230
L1.Kärnten -0.045385 0.020119 -2.256 0.024
L1.Niederösterreich 0.138372 0.080392 1.721 0.085
L1.Oberösterreich 0.162381 0.079173 2.051 0.040
L1.Salzburg 0.284389 0.040790 6.972 0.000
L1.Steiermark 0.059797 0.053774 1.112 0.266
L1.Tirol 0.159176 0.043425 3.666 0.000
L1.Vorarlberg 0.097986 0.038367 2.554 0.011
L1.Wien 0.072024 0.070547 1.021 0.307
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063662 0.048679 1.308 0.191
L1.Burgenland 0.025514 0.030074 0.848 0.396
L1.Kärnten 0.053120 0.015734 3.376 0.001
L1.Niederösterreich 0.192910 0.062870 3.068 0.002
L1.Oberösterreich 0.332013 0.061916 5.362 0.000
L1.Salzburg 0.035943 0.031899 1.127 0.260
L1.Steiermark 0.012141 0.042053 0.289 0.773
L1.Tirol 0.120880 0.033960 3.559 0.000
L1.Vorarlberg 0.066880 0.030004 2.229 0.026
L1.Wien 0.098172 0.055170 1.779 0.075
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172297 0.058628 2.939 0.003
L1.Burgenland 0.004770 0.036220 0.132 0.895
L1.Kärnten -0.065810 0.018949 -3.473 0.001
L1.Niederösterreich -0.104802 0.075718 -1.384 0.166
L1.Oberösterreich 0.205975 0.074570 2.762 0.006
L1.Salzburg 0.054447 0.038419 1.417 0.156
L1.Steiermark 0.247197 0.050647 4.881 0.000
L1.Tirol 0.502090 0.040900 12.276 0.000
L1.Vorarlberg 0.063935 0.036136 1.769 0.077
L1.Wien -0.077443 0.066445 -1.166 0.244
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.154270 0.064984 2.374 0.018
L1.Burgenland -0.002363 0.040147 -0.059 0.953
L1.Kärnten 0.062544 0.021003 2.978 0.003
L1.Niederösterreich 0.169389 0.083927 2.018 0.044
L1.Oberösterreich -0.055742 0.082654 -0.674 0.500
L1.Salzburg 0.208178 0.042584 4.889 0.000
L1.Steiermark 0.140260 0.056138 2.498 0.012
L1.Tirol 0.058349 0.045334 1.287 0.198
L1.Vorarlberg 0.147200 0.040054 3.675 0.000
L1.Wien 0.120598 0.073649 1.637 0.102
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.386177 0.038236 10.100 0.000
L1.Burgenland -0.004262 0.023623 -0.180 0.857
L1.Kärnten -0.020917 0.012358 -1.693 0.091
L1.Niederösterreich 0.202825 0.049383 4.107 0.000
L1.Oberösterreich 0.231479 0.048634 4.760 0.000
L1.Salzburg 0.036613 0.025056 1.461 0.144
L1.Steiermark -0.014574 0.033032 -0.441 0.659
L1.Tirol 0.089317 0.026675 3.348 0.001
L1.Vorarlberg 0.051523 0.023568 2.186 0.029
L1.Wien 0.044644 0.043335 1.030 0.303
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036909 0.110105 0.173294 0.139752 0.102769 0.081923 0.036239 0.211265
Kärnten 0.036909 1.000000 -0.025994 0.130881 0.049251 0.085164 0.443570 -0.066516 0.089784
Niederösterreich 0.110105 -0.025994 1.000000 0.314341 0.121354 0.275213 0.068649 0.154876 0.292913
Oberösterreich 0.173294 0.130881 0.314341 1.000000 0.213710 0.297597 0.167070 0.138534 0.239847
Salzburg 0.139752 0.049251 0.121354 0.213710 1.000000 0.125023 0.093003 0.106018 0.125245
Steiermark 0.102769 0.085164 0.275213 0.297597 0.125023 1.000000 0.135122 0.109103 0.038058
Tirol 0.081923 0.443570 0.068649 0.167070 0.093003 0.135122 1.000000 0.065235 0.151011
Vorarlberg 0.036239 -0.066516 0.154876 0.138534 0.106018 0.109103 0.065235 1.000000 -0.003019
Wien 0.211265 0.089784 0.292913 0.239847 0.125245 0.038058 0.151011 -0.003019 1.000000